package com.gc.flashview.utils;

import android.content.Context;
import android.os.Environment;

import com.gc.flashview.config.ImageConfig;

import java.io.File;

/**
 * <h3>Description</h3> flash view 文件工具类
 * TODO
 * <h3>Author</h3> luzhenbang
 * <h3>Date</h3> 2016/1/7 16:17
 * <h3>Copyright</h3> Copyright (c)2016 Shenzhen Tentinet Technology Co., Ltd. Inc. All rights reserved.
 */
public class FileUtil {
    public static String getAppPath(Context context) {
        String appPath = null;
        if (Environment.getExternalStorageState().equals(Environment.MEDIA_MOUNTED)) {
            appPath = Environment.getExternalStorageDirectory() + File.separator + ImageConfig.ROOT_CACHE;
        } else {
            appPath = Environment.getDataDirectory() + File.separator + context.getPackageName();
        }
        File file = new File(appPath);
        if (!file.exists()) {
            file.mkdirs();
        }
        return appPath;
    }

    /**
     *
     * 缓存文件
     * <h3>Version</h3> 1.0
     * <h3>CreateTime</h3> 2016/1/7,16:25
     * <h3>UpdateTime</h3> 2016/1/7,16:25
     * <h3>CreateAuthor</h3> luzhenbang
     * <h3>UpdateAuthor</h3>
     * <h3>UpdateInfo</h3> (此处输入修改内容,若无修改可不写.)
     * @return
     */
    public static File getImageCache(Context context) {
        String imageCache = getAppPath(context) + File.separator + ImageConfig.IMAGE_CACHE;
        File imageFile = new File(imageCache);
        if (!imageFile.exists()) {
            imageFile.mkdirs();
        }
        return  imageFile;

    }
}
